package com.baidu.service.impl;

import com.alibaba.fastjson.JSON;
import com.baidu.model.entity.ActivityModel;
import com.baidu.response.ResponseBody;
import com.baidu.service.InActivityController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.until.pagination.PaginationRequest;
import com.until.response.RestfulCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author user
 */
@Service
public class ActivityControllerImpl implements InActivityController {
    @Autowired
    private RestfulCode restfulCode;

    @Autowired
    private ResponseBody responseBody;

    @Autowired
    private ActivityServiceImpl activityControllerImpl;

    @Override
    public RestfulCode.CodeSatCode findAll(Integer id, PaginationRequest page) {
        RestfulCode.CodeSatCode userActionFailed =responseBody.USER_OPERATION_SUCCEEDED;
        PageInfo<ActivityModel> activityModelPageInfo = PageHelper.startPage(page.getPageNumber(), page.getPageSize()).doSelectPageInfo(() -> activityControllerImpl.selectByUserId(id));
        userActionFailed.setData(JSON.toJSON(activityModelPageInfo));
        return userActionFailed;
    }
}
